package com.zdxk.msgPush.msg.observer;

import com.alibaba.fastjson.JSONObject;
import com.zdxk.msgPush.msg.observer.interfaces.IObserver;
import com.zdxk.msgPush.websocket.netty.service.ChannelSupervise;

import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;


public class StockObserver implements IObserver {

    private String observerId;

    private Set<String> tsCodeSet = new ConcurrentSkipListSet<>();


    public StockObserver(String observerId) {
        this.observerId = observerId;
    }

    public boolean addTsCode(String tsCode){
        return this.tsCodeSet.add(tsCode);
    }

    @Override
    public String getObserverId() {
        return observerId;
    }

    @Override
    public boolean isMine(String tsCode) {
//        if(tsCodeSet.contains(tsCode)){
//            return true;
//        }else {
//            return false;
//        }
        return true;
    }

    @Override
    public boolean doNotify(String msg) {
        JSONObject obj = new JSONObject();
        obj.put("type","stockTrade");
        obj.put("msg",msg);
        ChannelSupervise.sendMsgbyChannelId(this.observerId,obj.toString());
        return true;
    }
}
